package cps_tree_package;


import interfaces.IItem;
import java.util.LinkedList;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author cogs
 */
public class OrdinaryNode {
    
    public IItem value;                                //wartosc przechowywanego elementu
    public OrdinaryNode parent;                 //rodzic
    public LinkedList<OrdinaryNode> child;      //dzieci
    public int supp;
    
    
    public OrdinaryNode() {
        parent = null;
        child = new LinkedList<OrdinaryNode>();
    }
    
    public OrdinaryNode(OrdinaryNode parent, IItem value){
        this();
        this.parent = parent;
        this.value = value;
    }
    
    
    public OrdinaryNode getParent(){
        return this.parent;
    }
    
    public void setParent(OrdinaryNode parent){
        this.parent = parent;
    }
    
    public IItem getValue(){
        return this.value;
    }
    
    public void setValue(IItem value){
        this.value = value;
    }
    
    public boolean isLeaf(){
        return child.isEmpty();
    }
    
    
    public OrdinaryNode addChild(IItem value){
        OrdinaryNode new_child = new OrdinaryNode(this, value);
        child.add(new_child);
        
        return new_child;
    }
    
    public OrdinaryNode getChild(int i){
        return child.get(i);
    }

    public OrdinaryNode removeChild(int i) {
        return child.remove(i);
    }

    public void removeChildren() {
        child.clear();
    }
}
